package tc;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;

import java.sql.*;
import java.util.*;

public class TableDemo extends JFrame {
	Connection con;
	Statement sta;
	String[] titles;
	Vector<Vector<String>> records;
	AbstractTableModel td;
	JTable table;
	JScrollPane js;

	public TableDemo() {

		int clos = 3;
		titles = new String[clos];
		for (int i = 0; i < clos; i++) {
			titles[i] = i + "列";
		}
		records = new Vector<Vector<String>>();
		records.removeAllElements();

		Vector<String> rowDatas = new Vector<String>();

		for (int i = 0; i < titles.length; i++) {
			rowDatas.add(i + "内容");

		}
		records.add(rowDatas);

		td = new AbstractTableModel() {
			public int getColumnCount() {
				return titles.length;
			}

			public int getRowCount() {
				return records.size();
			}

			public Object getValueAt(int row, int cloumn) {
				return ((Vector<String>) records.elementAt(row))
						.elementAt(cloumn);
			}

			public String getColumnName(int cloumn) {
				return titles[cloumn];
			}
		};

		table = new JTable(td);
		js = new JScrollPane(table);

		this.add(js);
		this.setVisible(true);
		this.setSize(400, 500);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public static void main(String[] args) {
		new TableDemo();
	}
}
